﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using ww.lis.lisbll.sam;

namespace ww.form.lis.sam.dic
{

    public partial class DiseaseForm : ww.form.wwf.SysBaseForm
    {
        DiseaseBLL bll = new DiseaseBLL();
        string currfp_id = "";//当前上级ID
        DataTable dtCurr = new DataTable();
        DataRowView rowCurr = null;

        public DiseaseForm()
        {
            InitializeComponent();
        }

        private void DiseaseForm_Load(object sender, EventArgs e)
        {
            GetTree("-1");
           
        }
        /// <summary>
        /// 树
        /// </summary>
        public void GetTree(string pid)
        {
            try
            {
                this.wwTreeView1.ZADataTable = this.bll.BllTypeDT(2);
                this.wwTreeView1.ZATreeViewRootValue = pid;//树 RootId　根节点值
                this.wwTreeView1.ZAParentFieldName = "fp_id";//上级字段名称
                this.wwTreeView1.ZADisplayFieldName = "fname";//显示字段名称
                this.wwTreeView1.ZAKeyFieldName = "ftype_id";//主键字段名称
                this.wwTreeView1.ZATreeViewShow();//显示树        
                try
                {
                    this.wwTreeView1.SelectedNode = wwTreeView1.Nodes[0].Nodes[0];
                }
                catch { }

            }
            catch (Exception ex)
            {
                ww.wwf.wwfbll.WWMessage.MessageShowError(ex.Message.ToString());
            }
        }
        private void GetCurrDT()
        {
            //dtCurr = new DataTable();
            if (dtCurr != null)
               dtCurr.Clear();
           dtCurr = this.bll.BllDiseaseDTByTypeid(currfp_id);
            bindingSourceObject.DataSource = dtCurr;
            
        }
        

        private void bindingSourceObject_PositionChanged(object sender, EventArgs e)
        {
            try
            {
                rowCurr = (DataRowView)bindingSourceObject.Current;//行
                /*
                string fname = "";
                if (rowCurrent != null)
                {
                    fname = drObject["fname"].ToString();
                    MessageBox.Show(fname);
                }*/
            }
            catch (Exception ex)
            {
                ww.wwf.wwfbll.WWMessage.MessageShowError(ex.Message.ToString());
            }
        }

       
       

        private void wwTreeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            try
            {
                currfp_id = e.Node.Name.ToString();
                GetCurrDT();
            }
            catch (Exception ex)
            {
                ww.wwf.wwfbll.WWMessage.MessageShowError(ex.ToString());
            }
        }

      

        private void toolStripButtonAdd_Click(object sender, EventArgs e)
        {
            try
            {
                DataRow dr = null;
                dr = this.dtCurr.NewRow();
                string guid = this.bll.DbGuid();
                dr["ftype_id"] = this.currfp_id;
                //dr["fp_id"] = this.currfp_id;
                dr["forder_by"] = "0";
                dr["fuse_if"] = "1";
                if (this.bll.BllDiseaseAdd(dr) > 0)
                {
                    this.dtCurr.Rows.Add(dr);
                    this.bindingSourceObject.Position = bindingSourceObject.Count;
                }
            }
            catch (Exception ex)
            {
                ww.wwf.wwfbll.WWMessage.MessageShowError(ex.Message.ToString());
            }
        }

        private void toolStripButtonS_Click(object sender, EventArgs e)
        {
            try
            {
                this.Validate();
                this.bindingSourceObject.EndEdit();
                for (int i = 0; i < this.dtCurr.Rows.Count; i++)
                {
                    this.bll.BllDiseaseUpdate(this.dtCurr.Rows[i]);

                }
                GetCurrDT();
            }
            catch (Exception ex)
            {
                ww.wwf.wwfbll.WWMessage.MessageShowError(ex.Message.ToString());
            }
        }

       
        private void toolStripButtonR_Click(object sender, EventArgs e)
        {
            GetTree("-1");
        }

        private void toolStripButtonDel_Click(object sender, EventArgs e)
        {
            try
            {
                if (ww.wwf.wwfbll.WWMessage.MessageDialogResult("是否真要删除此类型？"))
                {
                    if (this.bll.BllTypeDelete(rowCurr["ftype_id"].ToString()) > 0)
                        GetCurrDT();
                }
            }
            catch (Exception ex)
            {
                ww.wwf.wwfbll.WWMessage.MessageShowError(ex.Message.ToString());
            }
        }

        
    }
}